package com.itcast.mapper;

import com.github.pagehelper.Page;
import com.itcast.pojo.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface EmpMapper {
    /*
    //分页查询
    //方案一
    @Select("select emp.*,dept.name deptName from emp left join dept on emp.dept_id = dept.id limit #{index},#{pageSize};")
    List<Emp> pageQuery(@Param("index") Integer index, @Param("pageSize") Integer pageSize);
    //方案二
    @Select("select count(*) from emp left join dept on emp.dept_id = dept.id")
    Integer count();
    @Select("select emp.*,dept.name deptName from emp left join dept on emp.dept_id = dept.id")
    Page<Emp> pageQuery();*/

    /**
     * 分页查询(条件)
     * @param param
     * @return
     */
    //方案三
    Page<Emp> pageQuery(EmpQueryParam param);

    /**
     * 新增员工
     * @param emp
     */
    void insert(Emp emp);

    /**
     * 批量删除
     * @param ids
     */
    void deleteBatch(@Param("ids") List<Integer> ids);

    /**
     * 根据Id查询(基本信息)
     * @param id
     * @return
     */
    @Select("select id, username, password, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time from emp where id = #{id}")
    Emp getById(Integer id);

    /**
     * 根据Id查询(基本信息+工作经历)(连接查询)
     * @param id
     * @return
     */
    EmpDto getInfoById(Integer id);

    /**
     * 修改员工基本信息
     * @param empDto
     * @return
     */
    void update(EmpDto empDto);

    /**
     * 员工职位统计
     * @return
     */
    @Select("select case job when 1 then '班主任'\n" +
            "                when 2 then '讲师'\n" +
            "                when 3 then '学工主管'\n" +
            "                when 4 then '校验主管'\n" +
            "                when 5 then '咨询师'\n" +
            "                else '其他' end job\n" +
            "     ,count(*)  total\n" +
            "from emp group by job order by total ;")
    List<JobData> empJobData();

    /**
     * 员工性别统计
     * @return
     */
    @Select("select if (gender = 1 , '男性','女性') name\n" +
            "     ,count(*)  value\n" +
            "from emp group by gender")
    List<EmpGenderData> empGenderData();

    /**
     * 查询所有员工
     * @return
     */
    @Select("select id, username, password, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time from emp;")
    List<Emp> list();

    @Select("select id, username, password, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time from emp where username = #{username};")
    Emp login(Emp emp);

    @Select("select operate_log.*,emp.name operateEmpName\n" +
            "from operate_log left join emp on operate_emp_id = emp.id")
    Page<OperateLog> logList(Integer page, Integer pageSize);
}
